package org.tgcloud.group.core.ExportUtils;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;

/**
 * @author: zhy
 * @create: 2024-01-23 10:07
 * @description: 导出的样式工具
 */
public class ExportStyleUtils {

    public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook){
        // 固定标题样式
        HSSFCellStyle titleStyle = workbook.createCellStyle();
        titleStyle.setAlignment(HorizontalAlignment.CENTER);
        titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        titleStyle.setBorderBottom(BorderStyle.THIN);
        titleStyle.setBorderLeft(BorderStyle.THIN);
        titleStyle.setBorderRight(BorderStyle.THIN);
        titleStyle.setBorderTop(BorderStyle.THIN);
        HSSFFont titleFont = workbook.createFont();
        titleFont.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
        titleFont.setBold(true);
        titleFont.setFontHeightInPoints((short) 11);
        titleFont.setFontName("微软雅黑");
        titleStyle.setFont(titleFont);
        return titleStyle;
    }

    public static HSSFCellStyle getHeaderStyle(HSSFWorkbook workbook){
        // 标题样式
        HSSFCellStyle headerStyle = workbook.createCellStyle();
        headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex());
        // 填充效果（全景填充）
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        // 设置边框
        headerStyle.setBorderBottom(BorderStyle.THIN);
        headerStyle.setBorderLeft(BorderStyle.THIN);
        headerStyle.setBorderRight(BorderStyle.THIN);
        headerStyle.setBorderTop(BorderStyle.THIN);
        // 生成另一个字体
        HSSFFont font2 = workbook.createFont();
        font2.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
        font2.setBold(true);
        font2.setFontHeightInPoints((short) 11);
        font2.setFontName("微软雅黑");
        headerStyle.setFont(font2);
        return headerStyle;
    }

    public static HSSFCellStyle getNumberStyle(HSSFWorkbook workbook){
        // 生成数量类型的样式
        HSSFCellStyle numberStyle = workbook.createCellStyle();
        numberStyle.setAlignment(HorizontalAlignment.CENTER);
        numberStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        numberStyle.setBorderBottom(BorderStyle.THIN);
        numberStyle.setBorderLeft(BorderStyle.THIN);
        numberStyle.setBorderRight(BorderStyle.THIN);
        numberStyle.setBorderTop(BorderStyle.THIN);
        numberStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
        HSSFFont numberFont = workbook.createFont();
        numberFont.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
        numberFont.setBold(true);
        numberFont.setFontHeightInPoints((short) 11);
        numberFont.setFontName("微软雅黑");
        numberStyle.setFont(numberFont);
        return numberStyle;
    }

    public static HSSFCellStyle getPriceStyle(HSSFWorkbook workbook){
        // 生成价格类型的样式
        HSSFCellStyle priceStyle = workbook.createCellStyle();
        DataFormat dataFormat = workbook.createDataFormat();  //创建一个单元格数据格式
        priceStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));  //设置数据格式为数字
        priceStyle.setAlignment(HorizontalAlignment.CENTER);
        priceStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        priceStyle.setBorderBottom(BorderStyle.THIN);
        priceStyle.setBorderLeft(BorderStyle.THIN);
        priceStyle.setBorderRight(BorderStyle.THIN);
        priceStyle.setBorderTop(BorderStyle.THIN);
        HSSFFont priceFont = workbook.createFont();
        priceFont.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
        priceFont.setBold(true);
        priceFont.setFontHeightInPoints((short) 11);
        priceFont.setFontName("微软雅黑");
        priceStyle.setFont(priceFont);
        return priceStyle;
    }

}
